package com.woupla.city;

import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.convert.Converter;
import javax.inject.Inject;
import javax.inject.Named;

import com.woupla.model.City;
import com.woupla.model.Region;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author Dimitri Lebel
 * 
 */
@Named
@SessionScoped
public class CityMBean implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5265206894980185627L;

	@EJB
	private CityEJB cityEJB;
	@Inject
	private Logger log;
	private Converter regionConverter = new RegionConverter();

	private Region regionSelected = new Region();
	private String valueSearch;

	/**
	 * @return the citySelected
	 */
	public Region getRegionSelected() {
		return regionSelected;
	}

	/**
	 * @param citySelected
	 *            the citySelected to set
	 */
	public void setRegionSelected(Region regionSelected) {
		this.regionSelected = regionSelected;
	}

	/**
	 * @return the valueSearch
	 */
	public String getValueSearch() {
		return valueSearch;
	}

	/**
	 * @param valueSearch
	 *            the valueSearch to set
	 */
	public void setValueSearch(String valueSearch) {
		this.valueSearch = valueSearch;
	}

	/**
	 * @return the regionConverter
	 */
	public Converter getRegionConverter() {
		return regionConverter;
	}

	/**
	 * @param regionConverter
	 *            the regionConverter to set
	 */
	public void setRegionConverter(Converter regionConverter) {
		this.regionConverter = regionConverter;
	}

	public CityMBean() {
	}

	public List<Region> searchRegionLike() {
		log.log(Level.INFO,"Search "+ regionSelected.getLabel());
		return cityEJB.findRegionLike(regionSelected.getLabel());
	}
}
